﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using VioletDevelopmentLaboratory.Net.Web;

public partial class vboard_manager_membership_create : PageBase
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			PasswordQuestionDropDownList_DataBind();

			RoleCheckBoxList_DataBind();
		}
	}

	private void PasswordQuestionDropDownList_DataBind()
	{
		PasswordQuestionDropDownList.DataSource = VioletDevelopmentLaboratory.Net.Web.VUtility.GetVWebGlobalResource("Membership_PasswordQuestions").Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
		PasswordQuestionDropDownList.DataBind();
	}

	private void RoleCheckBoxList_DataBind()
	{
		if (Roles.Enabled)
		{
			RoleCheckBoxList.DataSource = Roles.GetAllRoles();
			RoleCheckBoxList.DataBind();
		}
	}
	protected void CreateUserButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			MembershipCreateStatus createResult;
			Membership.CreateUser(
				UserNameTextBox.Text,
				PasswordTextBox.Text,
				EmailTextBox.Text,
				PasswordQuestionDropDownList.SelectedValue,
				PasswordAnswerTextBox.Text,
				IsApprovedCheckBox.Checked,
				out createResult);

			switch (createResult)
			{
				case MembershipCreateStatus.Success:
					if (Roles.Enabled)
					{
						foreach (ListItem item in RoleCheckBoxList.Items)
						{
							if (item.Selected)
								Roles.AddUserToRole(UserNameTextBox.Text, item.Value);
						}
					}
					VUtility.ShowAlert(Page, createResult.ToString());
					break;
				default:
					VUtility.ShowAlert(Page, createResult.ToString());
					break;
			}
		}
	}
}
